package com.vanke.devops.domain.job;

import com.vanke.devops.domain.manager.dingding.DingDingManager;
import com.vanke.devops.domain.manager.shangyi.ShangYiManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 陈景阳
 * @since 2018/6/6
 */
@Component
public class SmsMonitorJob {

    @Autowired
    private ShangYiManager shangYiManager;

    @Autowired
    private DingDingManager dingDingManager;

    private boolean balanceIsWarning = false;

    /**
     * 一个小时监测一次
     */
    public void exec(){
        Integer balance = shangYiManager.getBalance();
        //TODO 阈值需要可以调整
        if(balance < 5000 && !balanceIsWarning){
            String text = String.format("短信余额已不足，请及时充值！！短信余额为：%s",balance);
            dingDingManager.sendText(text);
            balanceIsWarning = true;
        }else{
            //当短信充值后，值需要修改为false
            balanceIsWarning = false;
        }
    }

    /**
     * 每天9：30汇报下短信余额
     */
    public void exec1(){
        Integer balance = shangYiManager.getBalance();
        String text = String.format("当前短信余额为：%s",balance);
        dingDingManager.sendText(text);
    }
}
